package com.huijutao.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.huijutao.MyApp;
import com.huijutao.R;
import com.huijutao.beans.Huihui;

import java.util.ArrayList;

/**
 *惠惠Adapter
 */
public class HuihuiAdapter extends BaseAdapter {
    private Context context;
    private ArrayList<Huihui.ItemData> data;
    private LayoutInflater inflater=null;

    public HuihuiAdapter(Context context, ArrayList<Huihui.ItemData> data) {
        this.context = context;
        this.data = data;
    }

    @Override
    public int getCount() {
        if(data!=null)
        return data.size();

        return 0;
    }

    @Override
    public Huihui.ItemData getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder=null;
        inflater=LayoutInflater.from(context);
        if (convertView==null){
            convertView=inflater.inflate(R.layout.fragment_huihui_listview,null);
            holder=new ViewHolder();
            holder.text1= (TextView) convertView.findViewById(R.id.textView);
            holder.text2= (TextView) convertView.findViewById(R.id.textView1);
//            holder.text3= (TextView) convertView.findViewById(R.id.textView2);
            holder.text4= (TextView) convertView.findViewById(R.id.textView3);
            holder.image= (ImageView) convertView.findViewById(R.id.image);
            convertView.setTag(holder);
        }else{
            holder= (ViewHolder) convertView.getTag();
        }

        Huihui.ItemData hui= getItem(position);
        holder.text1.setText(hui.getTitle());
        holder.text2.setText(hui.getSub_title());
        holder.text4.setText(hui.getEnd_time());
        MyApp.mImageXutils.display(holder.image, hui.getImage_url());
        return convertView;
    }
    public class ViewHolder{
        TextView text1;
        TextView text2;
//        TextView text3;
        TextView text4;
        ImageView image;
    }
}
